package com.example.springbootexamples.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.jacoco.cli.internal.RunReport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    private Logger logger= LoggerFactory.getLogger(this.getClass());
// http://localhost:8080/login?username=admin&password=admin
    // http://localhost:8080/login?username=admin&password=admin
    @RequestMapping( value="/login",method = RequestMethod.GET)
    public String login(String username,String password){
        Subject subject= SecurityUtils.getSubject();
        a();
        //subject.login(new UsernamePasswordToken(username,password));
        logger.info("{} {} ",username,password);
        return "login.html";
    }
    @RequestMapping( value = "/login",method = RequestMethod.POST)
    public String loginPost(String username,String password){
        logger.info("{} {} ",username,password);
        Subject subject=SecurityUtils.getSubject();
        UsernamePasswordToken usernamePasswordToken=new UsernamePasswordToken(username,password);
        try {
            subject.login(usernamePasswordToken);
        }catch (Exception e){
            e.printStackTrace();
            return "login fail";
        }

        return username;
    }

    /*@RequestMapping(value = "t")
    public Object t(){
        return "t";
    }*/


    void a(){
        String a[]={"a,","b"};
        //new RunReport().r(a);
    }



}
